package cn.edu.ljl;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

//拦截器

public class LoginFiltre extends HttpFilter {
    public final static String LOGIN_STATUS = "LOGIN";
    public final static String LOGIN_CODE ="CODE";
    @Override
    public void doFilter(HttpServletRequest request,
                         HttpServletResponse response, FilterChain chain)
            throws java.io.IOException, ServletException {

        HttpSession session = request.getSession(true);
        Boolean status = (Boolean)session.getAttribute(LOGIN_STATUS);

        if(status==null||status.equals(Boolean.FALSE))
        {
            response.sendRedirect("/gittest/login.html");
        }else {
            chain.doFilter(request,response);
        }
    }
}
